package com.pearl.utils.generateTableOrViewFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class FileUtils {

  public FileUtils() {
  }

  public static boolean loadProps(String path, Properties props) {
    return loadProps(new File(path), props);
  }

  public static boolean loadProps(File file, Properties props) {
    FileInputStream is = null;

    try {
      is = new FileInputStream(file);
      props.load(is);
      return true;
    } catch (Exception var12) {
    } finally {
      if (is != null) {
        try {
          is.close();
        } catch (IOException var11) {
        }
      }

    }

    return false;
  }

  public static boolean saveProps(String path, Properties props) {
    return saveProps(new File(path), props);
  }

  public static boolean saveProps(File file, Properties props) {
    FileOutputStream out = null;

    try {
      out = new FileOutputStream(file);
      props.store(out, (String) null);
      return true;
    } catch (Exception var12) {
    } finally {
      if (out != null) {
        try {
          out.close();
        } catch (IOException var11) {
        }
      }

    }

    return false;
  }

  public static String readContent(String path) throws IOException {
    return readContent(new File(path));
  }

  public static String readContent(String path, String charsetName) throws IOException {
    return readContent(new File(path), charsetName);
  }

  public static String readContent(File file) throws IOException {
    return readContent(file, "utf-8");
  }

  public static String readContent(File file, String charsetName) throws IOException {
    byte[] bytesArray = new byte[(int) file.length()];
    FileInputStream fis = new FileInputStream(file);
    fis.read(bytesArray);
    fis.close();
    return new String(bytesArray, charsetName);
  }
}
